﻿<div class="wrap-container clearfix">
    <div class="column-content-detail">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <div class="layui-inline tool-btn">
                    <button class="layui-btn layui-btn-small layui-btn-normal addBtn" data-url="/Home/EditArticle"><i class="layui-icon">&#xe654;</i></button>
                    <button class="layui-btn layui-btn-small layui-btn-danger del_Btn"  data-id="list" data-url="/Home/deletearticle"><i class="layui-icon">&#xe640;</i></button>
                </div>
                <div class="layui-inline">
                    <input type="text" id="title" required lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
                </div>
                <button id="search" onclick="return false" class="layui-btn layui-btn-normal" lay-submit="search">搜索</button>
            </div>
        </form>
        <div class="layui-form" id="table-list" style="height:400px">
            <table id="list" class="layui-table"></table>
        </div>
    </div>
</div>
@section script{
    <script>
        $("#list").datagrid({
				 idField: 'id',
	            //singleSelect: false,
	            //rownumbers: true,
	            pagePosition: 'bottom',
	            pagination: true,//分页
	            pageSize: 100,//每页显示条数
	            pageList: [100, 150, 200, 250, 300, 350], //调整每页显示条数
	            fit: true,//宽高跟随父面板
	            fitColumns: true,//水平滚动条
	            nowrap: false,//折行显示
	            columns: [[
	            	{field:'check',checkbox:true, width: 100, align: 'center' },
                    { field: 'id', title: '文章编号', width: 180, align: 'center' },
                    { field: 'title', title: '文章名称', width: 180, align: 'center' },
                      { field: 'cname', title: '文章类别', width: 180, align: 'center' },
                    { field: 'recommend', title: '是否推荐', width: 180, align: 'center' },
                     { field: 'commentStatus', title: '评论状态', width: 180, align: 'center' },
	                { field: 'adminName', title: '发布人', width: 180, align: 'center' },
	                {field:'edit',title:'编辑',width:100,align:'center',
		                formatter: function(value,row,index){
		                    return '<button class="layui-btn layui-btn-mini layui-btn-normal edit-btn" data-id="' + row.id + '" data-url="/Home/EditArticle"><i class="layui-icon">&#xe642;</i></button>';
						}
	                }
	            ]],
            url: '/Home/articletable',
			})
        layui.use(['form'], function () {
            var form = layui.form();
            var option = "<option value=''>请选择类型</option>";
            $.post("/Home/parenttable", function (datas) {
                for (var i = 0; i < datas.length; i++) {
                    option += "<option value='" + datas[i].id + "'>" + datas[i].pname + "</option>";//拼接option中的内容
                    $("#Parentid").html(option);//将option的拼接内容加入select中，注意选择器是select的ID
                }
                form.render('select');
            }) 
            form.render();
        });
        $("#search").click(function(){
				$("#list").datagrid({
					queryParams: {
						title: $("#title").val()
					}
				});
        })
        //顶部批量删除
			$('.del_Btn').click(function () {
			    var id = "#" + $(this).attr("data-id");
			    var $table = $(id).datagrid('getChecked');
			    var no = new Array();
			    for (var i = 0; i < $table.length; i++) {
			        if (i == 0) {
			            no = "no=" + $table[i].id;
			        } else {
			            no += "&no=" + $table[i].id;
			        }
			    }
			    var url = $(this).attr('data-url');
			    layer.confirm('您确定要删除选中项?', function (index) {
			        //do something
			        $.get(url, no, function (data) {
			            layer.msg(data);
			            location.reload();
			        })
			        layer.close(index);
			    });
			    return false;
            });
    </script>
}